package ifosup.julien;

import java.util.ArrayList;

public class ConsoMessage implements Runnable {
	private ArrayList<String> listMessage = new ArrayList<String>();

	public void envoi(String message) {
		synchronized (listMessage) {
			listMessage.add(message);
			listMessage.notify();
		}
	}

	@Override
	public void run() {

		while (true) {
			synchronized (listMessage) {
				try {
					listMessage.wait();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}// synchronized
			if (!listMessage.isEmpty()) {
				for (String message : listMessage) {
					System.out.println(message);
				}
				listMessage.remove(0);
			}

		}// while

	}

}
